class Solution {
public:
    vector<int> decrypt(vector<int>& code, int k)
    {
        if (k == 0) return vector<int>(code.size(), 0);
        vector<int> tmp(code);
        int n = code.size();
        bool flag = false;
        if (k < 0) flag = true;

        for (int i = 0; i < n; i++)
        {
            int idx = (i + k + n) % n, st = (i - 1 + n) % n;
            if (!flag)
                idx = (i + k + n) % n, st = (i + 1) % n;
            if (flag) swap(idx, st);
            int sum = 0;
            for (int j = st, l = 0; l < abs(k); j = (j + 1) % n, l++)
                sum += tmp[j];
            code[i] = sum;
        }
        return code;
    }
};